import request from '@/utils/request'

/**
 * 获取资源列表
 */
export function getResourcesApi(params) {
  return request({
    url: '/api/resource/list',
    method: 'get',
    params
  })
}

/**
 * 添加资源
 */
export function addResourceApi(data) {
  return request({
    url: '/api/resource/add',
    method: 'post',
    data
  })
} 

/**
 * 验证码验证
 */
export function verifyCodeApi(data) {
  return request({
    url: '/api/resource/verify',
    method: 'get',
    params: data
  })
}

/**
 * 上传文件资源
 */
export function uploadFileApi(file) {
  const formData = new FormData();
  formData.append('file', file);
  
  return request({
    url: '/api/resource/uploadFile',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 增加资源下载量
 */
export function increaseDownloadCountApi(id) {
  return request({
    url: `/api/resource/increaseDownload/${id}`,
    method: 'get'
  })
}

/**
 * 增加资源阅读量
 */
export function increaseViewCountApi(id) {
  return request({
    url: `/api/resource/increaseView/${id}`,
    method: 'get'
  })
}
